package com.ss.android.article.base.feature.feed.presenter;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.TextView;

import com.bytedance.article.common.c.TTUtils;
import com.bytedance.common.utility.Logger;
import com.bytedance.common.utility.UIUtils;
import com.bytedance.frameworks.baselib.network.http.util.TaskInfo;
import com.ss.android.action.ArticleActionHelper;
import com.ss.android.action.b.FeedViewHolder;
import com.ss.android.article.base.app.AppData;
import com.ss.android.article.base.app.BizApplication;
import com.ss.android.article.base.feature.app.b.DBHelper;
import com.ss.android.article.base.feature.app.c.ImageManager;
import com.ss.android.article.base.feature.c.FeedContext;
import com.ss.android.article.base.feature.c.FeedItemBehavior;
import com.ss.android.article.base.feature.c.FeedPresenter;
import com.ss.android.article.base.feature.detail.model.ArticleDetail;
import com.ss.android.article.base.feature.e.ArticleShareHelper;
import com.ss.android.article.base.feature.favorite.FavoriteActivity;
import com.ss.android.article.base.feature.feed.FeedCellStyleConfig;
import com.ss.android.article.base.feature.feed.FeedOnMovedToScrapHeapListener;
import com.ss.android.article.base.feature.feed.vh.AdItemInVideoFeedViewHolder;
import com.ss.android.article.base.feature.feed.vh.AppAdViewHolder;
import com.ss.android.article.base.feature.feed.vh.ArticleFeedViewHolder;
import com.ss.android.article.base.feature.feed.vh.BaseFeedViewHolder;
import com.ss.android.article.base.feature.feed.vh.FeedMaskViewHolder;
import com.ss.android.article.base.feature.feed.vh.FeedStickViewHolder;
import com.ss.android.article.base.feature.feed.vh.FeedVideoViewHolder;
import com.ss.android.article.base.feature.feed.vh.LastReadItemHolder;
import com.ss.android.article.base.feature.feed.vh.LbsAdViewHolder;
import com.ss.android.article.base.feature.feed.vh.RecentViewHolder;
import com.ss.android.article.base.feature.feed.k;
import com.ss.android.article.base.feature.main.IFeedManager;
import com.ss.android.article.base.feature.model.Article;
import com.ss.android.article.base.feature.model.CellRef;
import com.ss.android.article.base.feature.video.IVideoController;
import com.ss.android.article.base.feature.video.IVideoControllerContext;
import com.ss.android.article.browser.R;
import com.ss.android.b.a.BaseAdsData;
import com.ss.android.common.ad.MobAdClickCombiner;
import com.ss.android.common.callback.CallbackCenter;
import com.ss.android.common.callback.SSCallback;
import com.ss.android.common.lib.MobClickCombiner;
import com.ss.android.common.load.AsyncLoader;
import com.ss.android.common.util.NetworkStatusMonitor;
import com.ss.android.image.AvatarLoader;
import com.ss.android.image.loader.ImageLoader;
import com.ss.android.image.loader.LoadImagePolicy;
import com.ss.android.j.ClickableBackgroundCompat;
import com.ss.android.newmedia.a.PopupToast;
import com.ss.android.newmedia.a.TimeFormatter;
import com.ss.android.newmedia.e.t;
import com.ss.android.newmedia.util.AppUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;

public class ArticleFeedPresenter implements FeedPresenter {
    final class ArticleDetailLoader implements AsyncLoader.LoaderProxy<String, Article, Void, Void, ArticleDetail> {
        private WeakReference<ArticleFeedPresenter> mRefArticleFeedPresenter;

        public ArticleDetailLoader(ArticleFeedPresenter articleFeedPresenter) {
            this.mRefArticleFeedPresenter = new WeakReference(articleFeedPresenter);
        }

        public final ArticleDetail doInBackground(String key, Article param, Void extra) {
            Log.d("ArticleDetailCache", "doInBackground()  key=" + key);
            return ArticleFeedPresenter.getArticleDetail(param);
        }

        public final void onLoaded(String key, Article param, Void extra, ArticleDetail result) {
            if (this.mRefArticleFeedPresenter != null && this.mRefArticleFeedPresenter.get() != null) {
                ArticleFeedPresenter articleFeedPresenter = this.mRefArticleFeedPresenter.get();
                if (result != null && !android.support.design.a.isTextEmpty(result.content) && param != null) {
                    param.isDetailLoaded = true;
                    String itemKey = param.getItemKey();
                    if (articleFeedPresenter.mArticleDetailCache.containsKey(itemKey)) {
                        articleFeedPresenter.mArticleDetailCache.put(itemKey, result);
                        if (Logger.debug()) {
                            Logger.d("ArticleDetailCache", "onDetailLoaded: key = " + itemKey
                                    + ", detail = " + result
                                    + " ArticleDetailCache Size = " + articleFeedPresenter.mArticleDetailCache.size());
                        }
                    }
                }
            }
        }
    }

    private int mActualLargeImageHeight;
    private int mMaxLargeImageHeight;
    private TaskInfo mTaskInfo;
    private ImageManager mImageManager;
    private ImageLoader mItemImageLoader;
    private ImageLoader mLargeImageLoader;
    private AvatarLoader mFeedAvatarLoader;
    private AvatarLoader mAdItemInVideoAvatarLoader;
    private t I;
    private WebArticlePreloadHelper mWebArticlePreloadHelper;
    private AsyncLoader<String, Article, Void, Void, ArticleDetail> mAsyncLoader;
    private SSCallback mMoreActionCallback = new SSCallback() {
        public final Object onCallback(Object[] args) {
            ArticleFeedPresenter.this.mLargeItemAvatarLoader.mIsNightMode = AppData.isNightMode();
            ArticleFeedPresenter.this.mOneOrThreeItemAvatarLoader.mIsNightMode = AppData.isNightMode();
            return null;
        }
    };
    private View.OnClickListener mLastReadOnClickListener = new View.OnClickListener() {
        @Override
        public final void onClick(View view) {
            if ("__all__".equals(ArticleFeedPresenter.this.mCategoryName)) {
                MobClickCombiner.onEvent(ArticleFeedPresenter.this.mContext, "new_tab", "last_read_click");
            } else {
                MobClickCombiner.onEvent(ArticleFeedPresenter.this.mContext, "category", "last_read_click");
            }

            ArticleFeedPresenter.this.mCellRefBeforeLastRead.l = false;
            if (ArticleFeedPresenter.this.mLastReadClickListener != null) {
                ArticleFeedPresenter.this.mLastReadClickListener.onClick(view);
            }

            if ("__all__".equals(ArticleFeedPresenter.this.mCategoryName)) {
                MobClickCombiner.onEvent(ArticleFeedPresenter.this.mContext, "new_tab", "refresh_last_read");
            } else {
                MobClickCombiner.onEvent(ArticleFeedPresenter.this.mContext, "category", "refresh_last_read_" + ArticleFeedPresenter.this.mCategoryName);
            }
        }
    };
    private View.OnClickListener mRecentItemClickListener = new View.OnClickListener() {
        @Override
        public final void onClick(View view) {
            Context context = view.getContext();
            Intent intent = new Intent(context, FavoriteActivity.class);
            intent.putExtra("bundle_position", 3);
            context.startActivity(intent);
        }
    };
    Context mContext;
    String mCategoryName;
    CellRef mCellRefBeforeLastRead;
    View.OnClickListener mLastReadClickListener;
    AvatarLoader mLargeItemAvatarLoader;
    AvatarLoader mOneOrThreeItemAvatarLoader;
    Map mArticleDetailCache;
    private Resources mResources;
    private LayoutInflater mLayoutInflater;
    private AppData mAppData;
    private NetworkStatusMonitor mNetworkMonitor;
    private List<CellRef> mCellRefList;
    private int mFeedType;
    private AtomicBoolean n;
    private FeedItemBehavior mFeedItemBehavior;
    private boolean showDeleteView = false;
    private ArticleActionHelper mArticleActionHelper;
    private TimeFormatter mTimeFormatter;
    private PopupToast mPopupToast;
    private ArticleShareHelper mArticleShareHelper;
    private IVideoControllerContext mVideoControllerContext;
    private com.ss.android.article.base.ui.DiggAnimationView mDiggAnimationView;
    private CellRef mLastReadCellRef;
    private int mActualItemImageWidth;
    private int mActualItemImageHeight;
    private int mActualLargeImageWidth;

    /**
     * AppAdViewHolder
     *
     * @param position
     * @param cellRef
     * @param convertView
     * @param parent
     * @return
     */
    private View getNewAdItemInVideoFeedConvertView(int position, CellRef cellRef, View convertView, ViewGroup parent) {
        AdItemInVideoFeedViewHolder holder;
        View contentView;
        if (convertView == null || !(convertView.getTag() instanceof AdItemInVideoFeedViewHolder)) {
            convertView = this.mLayoutInflater.inflate(com.ss.android.article.browser.R.layout.new_ad_item_in_video_feed, parent, false);
            holder = new AdItemInVideoFeedViewHolder(this.mContext, this.mFeedItemBehavior, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.n);
            holder.mAvatarLoader = this.mAdItemInVideoAvatarLoader;
            holder.mRoot = convertView.findViewById(com.ss.android.article.browser.R.id.root);
            holder.mContentWrapper = convertView.findViewById(com.ss.android.article.browser.R.id.contents_wrapper);
            holder.mDivider = convertView.findViewById(com.ss.android.article.browser.R.id.divider);
            holder.mDelete = convertView.findViewById(com.ss.android.article.browser.R.id.delete);
            holder.mRoot.setOnLongClickListener(null);
            convertView.setTag(holder);
            contentView = convertView;
        } else {
            Object tag = convertView.getTag();
            holder = new AdItemInVideoFeedViewHolder(this.mContext, this.mFeedItemBehavior, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.n);
            AdItemInVideoFeedViewHolder beforeHolder = (AdItemInVideoFeedViewHolder) tag;
            holder.M = beforeHolder.M;
            holder.mRoot = beforeHolder.mRoot;
            holder.mContentWrapper = beforeHolder.mContentWrapper;
            holder.mDelete = beforeHolder.mDelete;
            holder.mDivider = beforeHolder.mDivider;
            holder.mAdLargeImageLayout = beforeHolder.mAdLargeImageLayout;
            holder.mLargeImage = beforeHolder.mLargeImage;
            holder.mAdTitle = beforeHolder.mAdTitle;
            holder.mCoverTopShaow = beforeHolder.mCoverTopShaow;
            holder.mAdBottomLayout = beforeHolder.mAdBottomLayout;
            holder.mAdAvatar = beforeHolder.mAdAvatar;
            holder.mAdAvatarTv = beforeHolder.mAdAvatarTv;
            holder.mAdSourceTvName = beforeHolder.mAdSourceTvName;
            holder.mAdLabel = beforeHolder.mAdLabel;
            holder.mAdBtnLayout = beforeHolder.mAdBtnLayout;
            holder.mAppAdProgress = beforeHolder.mAppAdProgress;
            holder.mAdTv = beforeHolder.mAdTv;
            holder.mInfoLayoutGroup = beforeHolder.mInfoLayoutGroup;
            convertView.setTag(holder);
            contentView = convertView;
        }

        if (cellRef == null) {
            return contentView;
        }

        boolean reuseItem = holder.mCellRef == cellRef && android.support.design.a.reuseItem(contentView);
        if (cellRef.cellType == 0 && cellRef.Q == 0) {
            try {
                cellRef.reuseItem = reuseItem;
                holder.a(cellRef, position);
            } catch (Exception exception) {
                Logger.throwExceptionInDebug(exception);
            }

            boolean sendEveryItemShow = this.mAppData.sendEveryItemShow();
            if (reuseItem && !sendEveryItemShow && (Logger.debug())) {
                Logger.d("ArticleFeedPresenter", "skip show event for item view: " + position);
            }
            this.a(reuseItem, sendEveryItemShow, cellRef, cellRef.article, holder);
            return contentView;
        }

        String v2_4;
        JSONObject v16;
        if (cellRef.cellType == 10) {
            if (!reuseItem) {
                holder.B = null;
            }

            try {
                holder.a(cellRef, position);
            } catch (Exception v2_2) {
                Logger.throwExceptionInDebug(v2_2);
            }

            JSONObject jo = null;
            try {
                if (!android.support.design.a.isTextEmpty(cellRef.downloadAppAd.logExtra)) {
                    jo = new JSONObject();
                    jo.put("log_extra", cellRef.downloadAppAd.logExtra);
                    holder.feedCallAppAdLogExtra = cellRef.downloadAppAd.logExtra;
                }
                v16 = jo;
            } catch (Exception v2_2) {
                v16 = null;
            }
            if (!this.mAppData.sendEveryItemShow() && (reuseItem)) {
                if (Logger.debug()) {
                    Logger.d("ArticleFeedPresenter", "skip show event for ad view: " + position);
                }
            } else if (cellRef.downloadAppAd != null) {
                MobAdClickCombiner.onAdEvent(this.mContext, "feed_download_ad", "card_show", cellRef.downloadAppAd.id, 0, v16, 2);
                if (cellRef != null && cellRef.downloadAppAd != null) {
                    AppUtil.a(cellRef.downloadAppAd.trackUrlList, this.mContext);
                }
                MobAdClickCombiner.onAdEvent(this.mContext, "embeded_ad", "show", cellRef.downloadAppAd.id, 0, v16, 2);
            } else {
                if (Logger.debug()) {
                    Logger.d("ArticleFeedPresenter", "skip show event for ad view: " + position);
                }
            }

            v2_4 = "";
            if (cellRef.downloadAppAd != null) {
                if (!android.support.design.a.isTextEmpty((String) null)) {
                    v2_4 = null;
                } else if (cellRef.downloadAppAd.id > 0) {
                    v2_4 = String.valueOf(cellRef.downloadAppAd.id);
                }
            }

            holder.a(2, String.valueOf(cellRef.adId), v2_4, cellRef.logExtra);
            holder.adId = v2_4;
            return contentView;
        }

        if (cellRef.cellType == 0 && cellRef.Q == 3) {
            try {
                holder.a(cellRef, position);
            } catch (Exception e) {
                Logger.throwExceptionInDebug(e);
            }

            JSONObject jo = new JSONObject();
            try {
                if (!android.support.design.a.isTextEmpty(cellRef.feedCallAppAd.logExtra)) {
                    jo.put("log_extra", cellRef.feedCallAppAd.logExtra);
                    holder.feedCallAppAdLogExtra = cellRef.feedCallAppAd.logExtra;
                }
            } catch (Exception exception) {
            }

            if (!this.mAppData.sendEveryItemShow() && (reuseItem)) {
                if (Logger.debug()) {
                    Logger.d("ArticleFeedPresenter", "skip show event for ad view: " + position);
                }
            } else if (cellRef.feedCallAppAd != null) {
                MobClickCombiner.onEvent(this.mContext, "embeded_ad", "show", cellRef.feedCallAppAd.id, 0, jo);
                cellRef.feedCallAppAd.a(this.mContext, "card_show");
                AppUtil.a(cellRef.feedCallAppAd.trackUrlList, this.mContext);
            } else {
                if (Logger.debug()) {
                    Logger.d("ArticleFeedPresenter", "skip show event for ad view: " + position);
                }
            }

            String adId = "";
            if (cellRef.feedCallAppAd != null) {
                adId = String.valueOf(cellRef.feedCallAppAd.id);
            }
            holder.a(2, String.valueOf(cellRef.adId), adId, cellRef.logExtra);
            holder.adId = adId;
            return contentView;
        }
        holder.mDelete.setVisibility(this.showDeleteView ? View.VISIBLE : View.GONE);
        return contentView;
    }

    private void a(boolean arg8, boolean arg9, CellRef cellRef, Article arg11, FeedViewHolder feedViewHolder) {
        this.a(arg8, arg9, cellRef, arg11, feedViewHolder, false);
    }

    static ArticleDetail getArticleDetail(Article article) {
        if (article != null) {
            try {
                DBHelper dbHelper = DBHelper.getInstance(BizApplication.getApplication());
                ArticleDetail articleDetail = null;
                if (dbHelper != null) {
                    articleDetail = dbHelper.queryArticleDetail(article, false);
                }

                if (articleDetail != null && !android.support.design.a.isTextEmpty(articleDetail.content)) {
                    return articleDetail;
                }

                return ArticleQueryThread.getArticleDetail(dbHelper, article, false, null);
            } catch (Throwable throwable) {
                Logger.w("ArticleFeedPresenter", "get article detail exception: " + throwable);
            }
        }
        return null;
    }

    private void a(boolean arg14, boolean arg15,
                   CellRef cellRef, Article article,
                   FeedViewHolder feedViewHolder, boolean arg19) {
        int v2_2;
        String itemKey;
        if ((!arg14 || (arg15)) && (cellRef.statUrlList != null && cellRef.statUrlList.size() > 0)) {
            AppUtil.a(cellRef.statUrlList, this.mContext, false, 1);
        }

        JSONObject jo = new JSONObject();
        try {
            if (android.support.design.a.isTextEmpty(cellRef.logExtra)) {
            } else {
                jo.put("log_extra", cellRef.logExtra);
                feedViewHolder.feedCallAppAdLogExtra = cellRef.logExtra;
            }
        } catch (Exception v2) {
            jo = null;
        }

        if (cellRef.adId > 0 && (!arg14 || (arg15))) {
            MobAdClickCombiner.onAdEvent(this.mContext, "embeded_ad", "show", cellRef.adId, 0, jo, 2);
            AppUtil.a(cellRef.adTrackUrl, this.mContext);
        }

        boolean isZZCommentNotEmpty = article.zzcomment != null && !article.zzcomment.isEmpty();
        if ((article.comment != null || isZZCommentNotEmpty) && (!arg14 || (arg15))) {
            long commentId = isZZCommentNotEmpty ? article.zzcomment.get(0).commentId : article.comment.commentId;
            jo = new JSONObject();
            try {
                jo.put("has_zz_comment", isZZCommentNotEmpty ? 1 : 0);
                jo.put("gid", article.groupId);
                jo.put("item_id", article.itemId);
                if (isZZCommentNotEmpty) {
                    jo.put("mid", article.zzcomment.get(0).mediaId);
                }
            } catch (JSONException jsonException) {
                jsonException.printStackTrace();
            }

            if (this.mCategoryName.equals("__all__")) {
                MobClickCombiner.onEvent(this.mContext, "click_list_comment", "headline_comment_show", cellRef.adId, commentId, jo);
            } else if (!this.mCategoryName.equals("__favor__")
                    && !this.mCategoryName.equals("__pgc__")
                    && !this.mCategoryName.equals("__search__")) {
                MobClickCombiner.onEvent(this.mContext, "click_list_comment", this.mCategoryName + "_comment_show", cellRef.adId, commentId, jo);
            }
        }
        String adId = "";
        if (cellRef.adId > 0) {
            adId = String.valueOf(cellRef.adId);
        }

        itemKey = article.getItemKey();
        v2_2 = ArticleFeedViewHolder.a(cellRef, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.mNetworkMonitor);
        if (cellRef != null && feedViewHolder != null) {
            if (cellRef.stickStyle == 2) {
                feedViewHolder.a(1, 1);
            } else {
                if (arg19) {
                    feedViewHolder.a(3, 1);
                } else {
                    if (cellRef.article != null && ((cellRef.article.m()) || (cellRef.article.n()))) {
                        if (cellRef.article.gallaryFlag == 1) {
                            feedViewHolder.a(2, 3);
                        } else if (cellRef.article.gallaryFlag == 2) {
                            feedViewHolder.a(2, 1);
                        } else if (cellRef.article.gallaryFlag == 3) {
                            feedViewHolder.a(2, 2);
                        } else if (cellRef.article.gallaryFlag != 0) {
                        } else {
                            switch (android.support.design.a.a(cellRef.article, v2_2)) {
                                case 2: {
                                    feedViewHolder.a(2, 5);
                                    break;
                                }
                                case 3: {
                                    feedViewHolder.a(2, 4);
                                    break;
                                }
                                case 4: {
                                    feedViewHolder.a(2, 3);
                                    break;
                                }
                            }
                        }
                    } else if (cellRef.article != null && (cellRef.article.h())) {
                        v2_2 = android.support.design.a.a(cellRef.article, v2_2);
                        if (v2_2 == 4) {
                            if (cellRef.k()) {
                                feedViewHolder.a(3, 2);
                            } else {
                                feedViewHolder.a(3, 1);
                            }
                        } else if (v2_2 == 2) {
                            feedViewHolder.a(3, 3);
                        } else {
                        }
                    } else {
                        v2_2 = android.support.design.a.a(cellRef.article, v2_2);
                        if (v2_2 <= 0) {
                        } else {
                            feedViewHolder.a(1, v2_2);
                        }
                    }
                }
                Logger.d("feed_cell", "category: " + feedViewHolder.category + "  style: " + feedViewHolder.style);
            }
        }

        feedViewHolder.a(1, itemKey, String.valueOf(article.groupId), adId, "item_id",
                article.itemId, "aggr_type", article.aggrType, cellRef.logExtra);
        feedViewHolder.adId = adId;
        if (article.impressionTimestamp <= 0) {
            long ts = System.currentTimeMillis();
            if (ts > 0) {
                if (Logger.debug()) {
                    Logger.d("Article", "set impression : gid = " + article.groupId
                            + ", iid = " + article.itemId
                            + ", aggr_type = " + article.aggrType
                            + ", title = " + article.title + ", ts = " + ts);
                }

                article.impressionTimestamp = ts;
            }

            DBHelper dbHelper = DBHelper.getInstance(this.mContext);
            if (dbHelper == null) {
            } else if (article == null) {
            } else {
                ContentValues contentValues = new ContentValues();
                contentValues.put("ss_op_key", Integer.valueOf(115));
                contentValues.put("impression_timestamp", Long.valueOf(article.impressionTimestamp));
                contentValues.put("group_id", Long.valueOf(article.groupId));
                dbHelper.asyncUpdate(contentValues);
            }
        } else {
            if (!Logger.debug()) {
            } else {
                Logger.v("ArticleFeedPresenter", "has impression : gid = " + article.groupId
                        + ", title = " + article.title
                        + ", ts = " + article.impressionTimestamp);
            }
        }

        if (article.f() && this.mNetworkMonitor.isNetworkOn() && this.mAsyncLoader != null) {
            String itemKey1 = article.getItemKey();
            this.mArticleDetailCache.put(itemKey1, null);
            this.mAsyncLoader.addTask(itemKey1, article, null, null);
        } else if (!this.n.get() && this.mAsyncLoader != null) {
            String itemKey1 = article.getItemKey();
            this.mArticleDetailCache.put(itemKey1, null);
            this.mAsyncLoader.addTask(itemKey1, article, null, null);
        }

        if (this.mWebArticlePreloadHelper != null && cellRef.adId <= 0) {
            if (article != null
                    && article.hasArticleUrl()
                    && article.shouldPreload(mWebArticlePreloadHelper.mNetworkMonitor.mCurrrentNetworkType)
                    && article != mWebArticlePreloadHelper.mArticle) {
                mWebArticlePreloadHelper.mPreloadQueue.remove(Long.valueOf(article.groupId));
                mWebArticlePreloadHelper.mPreloadQueue.put(Long.valueOf(article.groupId), article);
            }
            mWebArticlePreloadHelper.preload();
        }
    }

    public final int getItemViewType(CellRef cellRef) {
        int v2 = 2;
        int v0 = 1;
        switch (cellRef.cellType) {
            case -1: {
                v0 = 5;
                break;
            }
            case 0: {
                if (cellRef.adId > 0 && cellRef.Q != 0) {
                    if (cellRef.Q == 3) {
                        return v0;
                    } else {
                        return 0;
                    }
                }
                if (cellRef.stickStyle == v2) {
                    return 7;
                }

                if (ArticleFeedViewHolder.a(cellRef, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.mNetworkMonitor) != v2) {
                    return v0;
                }

                if (cellRef.videoStyle <= v2) {
                    return v0;
                }

                v0 = 8;
                break;
            }
            case 3: {
                v0 = v2;
                break;
            }
            case 1:
            case 10:
            case 16:
            case 30: {
                break;
            }
            case 32: {
                v0 = 9;
                break;
            }
            default: {
                return 0;
            }
        }

        return v0;
    }

    public final View getView(int position, View convertView, ViewGroup parent) {
        if (android.support.design.a.isEmptyCollection(this.mCellRefList)) {
            return null;
        } else {
            CellRef cellRef = this.mCellRefList.get(position);
            switch (cellRef.cellType) {
                case -11: //recent read
                    if (convertView == null || !(convertView.getTag() instanceof RecentViewHolder)) {
                        convertView = LayoutInflater.from(this.mContext).inflate(R.layout.dj, parent, false);
                        RecentViewHolder holder = new RecentViewHolder();
                        holder.imageView = convertView.findViewById(R.id.ul);
                        holder.imageView.setBackgroundDrawable(ContextCompat.getDrawable(mContext, R.drawable.arrow_right));
                        convertView.setTag(holder);
                    } else {
                        convertView.getTag();
                    }
                    AbsListView.LayoutParams lp = (AbsListView.LayoutParams) convertView.getLayoutParams();
                    lp.height = AbsListView.LayoutParams.WRAP_CONTENT;
                    convertView.setLayoutParams(lp);
                    convertView.setOnClickListener(this.mRecentItemClickListener);
                    convertView.setClickable(true);
                    break;
                case -10:
                    if (convertView == null || !(convertView.getTag() instanceof FeedMaskViewHolder)) {
                        convertView = LayoutInflater.from(this.mContext).inflate(R.layout.feed_mask_layout, parent, false);
                        FeedMaskViewHolder tag = new FeedMaskViewHolder();
                        tag.firstLine = convertView.findViewById(R.id.feed_flash_mask_view_title);
                        tag.secondLine = convertView.findViewById(R.id.feed_flash_mask_view_subtitle);
                        convertView.setTag(tag);
                    } else {
                        convertView.getTag();
                    }
                    AbsListView.LayoutParams lp2 = (AbsListView.LayoutParams) convertView.getLayoutParams();
                    lp2.height = AbsListView.LayoutParams.WRAP_CONTENT;
                    convertView.setLayoutParams(lp2);
                    break;
                case -1:
                    convertView = this.getLastReadNotifyLayout(position, convertView, parent);
                    break;
                case 0:
                    if (cellRef.adId > 0 && cellRef.Q != 0) {
                        if (cellRef.Q != 3) {

                        } else if (cellRef.videoChannelAdType == 1) {
                            convertView = this.getNewAdItemInVideoFeedConvertView(position, cellRef, convertView, parent);
                        } else {
                            convertView = this.getEmbeddedAdConvertView(position, cellRef, convertView, parent);
                        }
                        break;
                    } else if (cellRef.stickStyle == 2) {
                        convertView = this.getFeedStickConvertView(position, cellRef, convertView, parent);
                        break;
                    } else if (ArticleFeedViewHolder.a(cellRef, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.mNetworkMonitor) == 2
                            && cellRef.videoStyle > 2) {
                        //视频走到了这里
                        convertView = this.getFeedVideoConvertView(position, cellRef, convertView, parent);
                        break;
                    } else if (cellRef.videoChannelAdType == 1) {
                        convertView = this.getNewAdItemInVideoFeedConvertView(position, cellRef, convertView, parent);
                        break;
                    } else {
                        //三图走到了这里
                        convertView = this.c(position, cellRef, convertView, parent);
                        break;
                    }
                case 1:
                    convertView = this.getImage3ConvertView(position, cellRef, convertView, parent);
                    break;
                case 9:
                    if (convertView == null) {
                        convertView = new View(this.mContext);
                        convertView.setVisibility(View.GONE);
                    }
                    break;
                case 10:
                    if (cellRef.videoChannelAdType == 1) {
                        convertView = this.getNewAdItemInVideoFeedConvertView(position, cellRef, convertView, parent);
                    } else {
                        convertView = this.getFeedDownloadConvertView(position, cellRef, convertView, parent);
                    }
                    break;
                case 16:
                    convertView = this.getEmbeddedAdConvertView(position, cellRef, convertView, parent);
                    break;
                case 30:
                    convertView = this.getLbsAdConvertView(position, cellRef, convertView, parent);
                    break;
            }

            if (convertView != null) {
                if (this.mCellRefList.get(position).cellType != -1) {
                    FeedCellStyleConfig.setCellBackgroundColor(convertView);
                }
                convertView.setTag(com.ss.android.article.browser.R.id.item_reuse_tag, Boolean.FALSE);
            }


            if (cellRef.cellType != 0) {
                if (cellRef.cellType != 10) {
                    return convertView;
                }

                if (cellRef.downloadAppAd == null) {
                    return convertView;
                }

                int v1_3 = cellRef.downloadAppAd.preloadWeb == 3 ? 1 : 0;
                if (v1_3 == 0) {
                    return convertView;
                }

                if (!this.mNetworkMonitor.isWifiOn()) {
                    return convertView;
                }

                HashMap v1_2 = new HashMap();
                v1_2.put("TOUTIAO-PRELOAD", "*");
                this.I.a(cellRef.downloadAppAd.webUrl, v1_2);
            } else if (cellRef.article != null) {
                int v3 = 1;
                if (cellRef.article.preloadWeb != 3) {
                    v3 = 0;
                }

                if (v3 == 0) {
                    return convertView;
                }

                if (!this.mNetworkMonitor.isWifiOn()) {
                    return convertView;
                }
                HashMap<String,String> map = new HashMap();
                map.put("TOUTIAO-PRELOAD", "*");
                this.I.a(cellRef.article.articleUrl, map);
            }
            return convertView;
        }
    }

    public final void setLastReadClickListener(View.OnClickListener onClickListener) {
        this.mLastReadClickListener = onClickListener;
    }

    public final void a(View arg5) {
        Object v3 = null;
        if (arg5 != null) {
            Object v1 = arg5.getTag();
            if ((v1 instanceof k)) {
                Object v0 = v1;
                if (((k) v0).d()) {
                    ((k) v0).loadImage();
                    ((k) v0).e();
                }
            }

            if (!(v1 instanceof ArticleFeedViewHolder)) {
                return;
            }

            if (this.mAsyncLoader == null) {
                return;
            }

            CellRef v0_1 = ((ArticleFeedViewHolder) v1).mCellRef;
            if (v0_1 == null) {
                return;
            }

            if (v0_1.article == null) {
                return;
            }

            String itemKey = v0_1.article.getItemKey();
            if (this.mArticleDetailCache.get(itemKey) != null) {
                return;
            }

            if (this.mAsyncLoader.isInQueue(itemKey)) {
                return;
            }

            this.mArticleDetailCache.put(itemKey, null);
            this.mAsyncLoader.addTask(itemKey, v0_1.article, null, null);
        }
    }

    public final void setFeedContext(FeedContext feedContext) {
        if (feedContext != null) {
            this.mContext = feedContext.mContext;
            this.mResources = this.mContext.getResources();
            this.mLayoutInflater = LayoutInflater.from(this.mContext);
            this.mAppData = AppData.getInstance();
            this.mCellRefList = feedContext.mCellRefList;
            this.mCategoryName = feedContext.mCategoryId;
            this.mFeedType = feedContext.mFeedType;
            this.mNetworkMonitor = feedContext.mNetworkMonitor;
            this.I = com.ss.android.newmedia.e.t.inst();
            this.mAsyncLoader = new AsyncLoader(32, 1, new ArticleDetailLoader(this));
            this.mArticleDetailCache = new HashMap();
            if ((this.mContext instanceof IFeedManager)) {
                this.mWebArticlePreloadHelper = ((IFeedManager) this.mContext).getPreloadHelper();
            }

            this.n = new AtomicBoolean(false);
            this.mArticleActionHelper = feedContext.mArticleActionHelper;
            this.mFeedItemBehavior = feedContext.mFeedItemBehavior;
            if ((this.mContext instanceof IVideoControllerContext)) {
                this.mVideoControllerContext = (IVideoControllerContext) this.mContext;
            }

            this.mTimeFormatter = new TimeFormatter(this.mContext);
            this.mPopupToast = feedContext.mPopupToast;
            this.mDiggAnimationView = feedContext.mDiggAnimationView;
            int videoDiggAuthorSize = this.mResources.getDimensionPixelSize(R.dimen.video_digg_author_size);
            int dp16 = ((int) UIUtils.dp2px(this.mContext, 16f));
            this.mArticleShareHelper = feedContext.mArticleShareHelper;
            int itemImageHeight = this.mResources.getDimensionPixelSize(R.dimen.item_image_height);
            int itemImageWidth = this.mResources.getDimensionPixelSize(R.dimen.item_image_width);
            int screenWidth = TTUtils.getScreenWidth(this.mContext);
            int screenHeight = TTUtils.getScreenHeight(this.mContext);
            int itemImageTotalPadding = this.mResources.getDimensionPixelOffset(R.dimen.item_image_total_padding);
            int feedItemHorizontalMargin = this.mResources.getDimensionPixelOffset(R.dimen.feed_item_horizontal_margin) << 1;
            this.mActualItemImageWidth = (screenWidth - itemImageTotalPadding) / 3;
            this.mActualItemImageHeight = itemImageHeight * this.mActualItemImageWidth / itemImageWidth;
            this.mActualLargeImageWidth = screenWidth - feedItemHorizontalMargin;
            this.mActualLargeImageHeight = screenWidth - this.mResources.getDimensionPixelOffset(R.dimen.feed_appad_pager_margin_left) - this.mResources.getDimensionPixelOffset(R.dimen.feed_appad_pager_margin_right);
            if ("__all__".equals(this.mCategoryName)) {
                this.mMaxLargeImageHeight = this.mActualLargeImageWidth;
            } else {
                if (screenHeight > 0) {
                    screenWidth = screenHeight;
                }
                this.mMaxLargeImageHeight = screenWidth * 2;
            }

            this.mTaskInfo = new TaskInfo();
            this.mImageManager = new ImageManager(this.mContext);
            this.mItemImageLoader = new ImageLoader(this.mContext, this.mTaskInfo, 16, 20, 2, this.mImageManager, this.mActualItemImageWidth, this.mActualItemImageHeight);
            this.mLargeImageLoader = new ImageLoader(this.mContext, this.mTaskInfo, 8, 2, this.mImageManager, this.mActualLargeImageWidth, this.mMaxLargeImageHeight);
            this.mLargeItemAvatarLoader = new AvatarLoader(this.mTaskInfo, this.mImageManager, videoDiggAuthorSize << 1, videoDiggAuthorSize, 32, 4);
            this.mLargeItemAvatarLoader.mIsNightMode = AppData.isNightMode();
            this.mOneOrThreeItemAvatarLoader = new AvatarLoader(this.mTaskInfo, this.mImageManager, dp16 << 1, dp16, 16, 2);
            this.mOneOrThreeItemAvatarLoader.mIsNightMode = AppData.isNightMode();
            itemImageTotalPadding = this.mResources.getDimensionPixelSize(R.dimen.feed_user_avatar_size);
            this.mFeedAvatarLoader = new AvatarLoader(com.ss.android.article.browser.R.drawable.feed_user, this.mTaskInfo, this.mImageManager, itemImageTotalPadding, itemImageTotalPadding, true);
            this.mAdItemInVideoAvatarLoader = new AvatarLoader(this.mTaskInfo, this.mImageManager, dp16 << 1, dp16, 16, 2);
            CallbackCenter.addCallback(com.ss.android.j.b.callbackTypeNightModeChanged, this.mMoreActionCallback);
        }
    }

    public final void setLoadImagePolicy(LoadImagePolicy policy) {
        if (this.mItemImageLoader != null) {
            this.mItemImageLoader.a(policy);
        }

        if (this.mLargeImageLoader != null) {
            this.mLargeImageLoader.a(policy);
        }

        if (this.mFeedAvatarLoader != null) {
            this.mFeedAvatarLoader.b = policy != LoadImagePolicy.NEVER;
        }

        if (this.mLargeItemAvatarLoader != null) {
            this.mLargeItemAvatarLoader.b = policy != LoadImagePolicy.NEVER;
        }

        if (this.mOneOrThreeItemAvatarLoader != null) {
            this.mOneOrThreeItemAvatarLoader.b = policy != LoadImagePolicy.NEVER;
        }
    }

    public final void a(boolean arg2) {
        if (this.n.get() != arg2 && (!AppData.getInstance().getAbSettings().shouldLoadImageWhenFling() || !arg2)) {
            this.n.set(arg2);
        }
    }

    private View getLastReadNotifyLayout(int position, View convertView, ViewGroup parent) {
        String v3_1;
        CellRef cellRef;
        long v10 = 3600000;
        LastReadItemHolder lastReadItemHolder;
        if (convertView == null || !(convertView.getTag() instanceof LastReadItemHolder)) {
            int layoutId = TextUtils.equals("question_and_answer", this.mCategoryName) ? R.layout.last_read_notify_wenda_layout : R.layout.last_read_notify_layout;
            View itemView = LayoutInflater.from(this.mContext).inflate(layoutId, parent, false);
            lastReadItemHolder = new LastReadItemHolder();
            Context context = this.mContext;
            lastReadItemHolder.mRootView = (ViewGroup) itemView;
            lastReadItemHolder.mTopDivider = lastReadItemHolder.mRootView.findViewById(com.ss.android.article.browser.R.id.top_divider);
            lastReadItemHolder.mBottomDivider = lastReadItemHolder.mRootView.findViewById(com.ss.android.article.browser.R.id.bottom_divider);
            lastReadItemHolder.mDesc = lastReadItemHolder.mRootView.findViewById(com.ss.android.article.browser.R.id.desc);
            lastReadItemHolder.mRefresh = lastReadItemHolder.mRootView.findViewById(com.ss.android.article.browser.R.id.refresh);
            lastReadItemHolder.mLastReadRefreshIcon = lastReadItemHolder.mRootView.findViewById(com.ss.android.article.browser.R.id.last_read_refresh_icon);
            AppData.getInstance();
            lastReadItemHolder.mContext = context;
            lastReadItemHolder.mTimeMinute = context.getString(com.ss.android.article.browser.R.string.ss_time_minute);
            lastReadItemHolder.mTimeHour = context.getString(com.ss.android.article.browser.R.string.ss_time_hour);
            lastReadItemHolder.mFeedLastReadRecent = context.getString(com.ss.android.article.browser.R.string.feed_last_read_recent);
            lastReadItemHolder.mFeedLastReadDescTimeSuffix = lastReadItemHolder.mContext.getString(com.ss.android.article.browser.R.string.feed_last_read_desc_time_suffix);
            lastReadItemHolder.mFeedLastReadDescTooEarly = lastReadItemHolder.mContext.getString(com.ss.android.article.browser.R.string.feed_last_read_desc_too_early);
            lastReadItemHolder.mFeedLastReadRefresh = lastReadItemHolder.mContext.getString(com.ss.android.article.browser.R.string.feed_last_read_refresh);
            lastReadItemHolder.mFeedLastReadRefreshTooEarly = lastReadItemHolder.mContext.getString(com.ss.android.article.browser.R.string.feed_last_read_refresh_too_early);
            itemView.setTag(lastReadItemHolder);
            itemView.setOnClickListener(this.mLastReadOnClickListener);
            convertView = itemView;
        } else {
            lastReadItemHolder = (LastReadItemHolder) convertView.getTag();
            ViewGroup.LayoutParams v1 = convertView.getLayoutParams();
            ((AbsListView.LayoutParams) v1).height = -2;
            convertView.setLayoutParams(v1);
        }

        cellRef = this.mCellRefList.get(position);
        if ((cellRef.B) || (cellRef.D)) {
            convertView.setOnClickListener(this.mLastReadOnClickListener);
            convertView.setClickable(true);
            if ((this.mContext instanceof IFeedManager)) {
                ((IFeedManager) this.mContext).onLastReadShow();
            }
        } else {
            convertView.setOnClickListener(null);
            convertView.setClickable(false);
        }

        int v1_2 = cellRef != null || !android.support.design.a.reuseItem(convertView) ? 0 : 1;
        if (cellRef != null) {
            try {
                if (cellRef.cellType != -1) {

                } else {
                    boolean isNightMode = AppData.isNightMode();
                    if (isNightMode != lastReadItemHolder.mIsNightMode) {
                        lastReadItemHolder.mRootView.setBackgroundResource(com.ss.android.article.browser.R.drawable.last_read_notify_bg);
                        if (lastReadItemHolder.mTopDivider != null) {
                            lastReadItemHolder.mTopDivider.setBackgroundColor(ContextCompat.getColor(lastReadItemHolder.mContext, R.color.feed_last_read_divider));
                        }

                        if (lastReadItemHolder.mBottomDivider != null) {
                            lastReadItemHolder.mBottomDivider.setBackgroundColor(ContextCompat.getColor(lastReadItemHolder.mContext, R.color.feed_last_read_divider));
                        }

                        lastReadItemHolder.mDesc.setTextColor(ContextCompat.getColor(lastReadItemHolder.mContext, R.color.feed_last_read_des));
                        lastReadItemHolder.mRefresh.setTextColor(ContextCompat.getColor(lastReadItemHolder.mContext, R.color.feed_last_read_refresh));
                        lastReadItemHolder.mLastReadRefreshIcon.setBackgroundDrawable(ContextCompat.getDrawable(lastReadItemHolder.mContext, R.drawable.refresh_lasttime_textpage));
                        lastReadItemHolder.mIsNightMode = isNightMode;
                    }

                    if (cellRef.B) {
                        lastReadItemHolder.mDesc.setText(String.format(lastReadItemHolder.mFeedLastReadDescTooEarly, Integer.valueOf(24)));
                        lastReadItemHolder.mRefresh.setText(lastReadItemHolder.mFeedLastReadRefreshTooEarly);
                    } else {
                        TextView v6 = lastReadItemHolder.mDesc;
                        long v4 = System.currentTimeMillis() - ((CellRef) cellRef).C;
                        if (v4 < 600000) {
                            v3_1 = lastReadItemHolder.mFeedLastReadRecent;
                        } else if (v4 < v10) {
                            v3_1 = v4 / 60000 + lastReadItemHolder.mTimeMinute + lastReadItemHolder.mFeedLastReadDescTimeSuffix;
                        } else {
                            v4 /= 3600000;
                            if (v4 >= 24) {
                                v4 = 23;
                            }

                            v3_1 = v4 + lastReadItemHolder.mTimeHour + lastReadItemHolder.mFeedLastReadDescTimeSuffix;
                        }

                        v6.setText(v3_1);
                        lastReadItemHolder.mRefresh.setText(lastReadItemHolder.mFeedLastReadRefresh);
                        if (cellRef.D) {
                        } else {
                            lastReadItemHolder.mRefresh.setVisibility(View.GONE);
                            lastReadItemHolder.mDesc.setTextColor(ContextCompat.getColor(lastReadItemHolder.mContext, R.color.ssxinzi3));
                            lastReadItemHolder.mLastReadRefreshIcon.setVisibility(View.GONE);
                        }
                    }
                }
            } catch (Exception ex) {
                Logger.throwExceptionInDebug(ex);
            }
        }
        boolean v0_3 = this.mAppData.sendEveryItemShow();
        if (v1_2 == 0 || (v0_3)) {
            if ("__all__".equals(this.mCategoryName)) {
                MobClickCombiner.onEvent(this.mContext, "new_tab", "last_read_show");
            } else {
                MobClickCombiner.onEvent(this.mContext, "category", "last_read_show");
            }
        }

        return convertView;
    }

    private View getFeedVideoConvertView(int position, CellRef cellRef, View convertView, ViewGroup container) {
        FeedVideoViewHolder holder;
        if (convertView == null) {
            convertView = this.mLayoutInflater.inflate(com.ss.android.article.browser.R.layout.feed_video_layout, container, false);
            holder = new FeedVideoViewHolder(this.mContext, this.mNetworkMonitor, this.mFeedItemBehavior, this.mArticleActionHelper,
                    this.mFeedType, this.mTimeFormatter, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.n,
                    this.mPopupToast, this.mDiggAnimationView);
            holder.mArticleShareHelper = this.mArticleShareHelper;
            holder.mLargeItemAvatarLoader = this.mLargeItemAvatarLoader;
            holder.mOneOrThreeItemAvatarLoader = this.mOneOrThreeItemAvatarLoader;
            holder.initView(convertView);
            convertView.setTag(holder);
        } else {
            holder = (FeedVideoViewHolder) convertView.getTag();
        }

        boolean v2 = holder.mCellRef == cellRef && android.support.design.a.reuseItem(convertView);
        if ((this.mAppData.getAbSettings().isVideoListShare()) && v2 && holder.bf == 2) {
            holder.a(0);
            holder.be = true;
        }

        try {
            cellRef.reuseItem = v2;
            holder.a(cellRef, position);
        } catch (Exception e) {
            Logger.throwExceptionInDebug(e);
        }
        holder.mDelete.setVisibility(this.showDeleteView ? View.VISIBLE : View.GONE);
        Article article = cellRef.article;
        boolean v3_1 = this.mAppData.sendEveryItemShow();
        if (v2 && !v3_1 && Logger.debug()) {
            Logger.d("ArticleFeedPresenter", "skip show event for item view: " + position);
        }
        this.a(v2, v3_1, cellRef, article, ((FeedViewHolder) holder), true);
        return convertView;
    }

    public final int getViewTypeCount() {
        return 12;
    }

    public final void onMovedToScrapHeap(View view) {
        if (view != null) {
            Object tag = view.getTag();
            if ((tag instanceof FeedOnMovedToScrapHeapListener)) {
                try {
                    ((FeedOnMovedToScrapHeapListener) tag).onMovedToScrapHeap();
                } catch (Exception e) {
                    Logger.throwExceptionInDebug(e);
                }
            }

            if (!(tag instanceof ArticleFeedViewHolder)) {
                return;
            }

            CellRef cellRef = ((ArticleFeedViewHolder) tag).mCellRef;
            if (cellRef == null) {
                return;
            }

            if (cellRef.article == null) {
                return;
            }

            String itemKey = cellRef.article.getItemKey();
            this.mArticleDetailCache.remove(itemKey);
            if (Logger.debug()) {
                Logger.d("ArticleDetailCache", "remove key = " + itemKey);
            }
        }
    }

    public final void onHiddenStatusChanged(boolean visible) {
        this.showDeleteView = visible;
    }

    public final boolean b(CellRef cellRef) {
        if (cellRef != null && cellRef.cellType == 0 && cellRef.article != null) {
            if ((cellRef.article.f()) && this.mAsyncLoader != null) {
                this.mArticleDetailCache.put(cellRef.article.getItemKey(), null);
                this.mAsyncLoader.addTask(cellRef.article.getItemKey(), cellRef.article, null, null);
                return true;
            }
        }
        return false;
    }

    private View c(int position, CellRef cellRef, View convertView, ViewGroup parent) {
        ArticleFeedViewHolder holder;
        convertView = convertView == null || convertView.getTag() instanceof BaseFeedViewHolder ? convertView : null;
        if (convertView == null) {
            convertView = this.mLayoutInflater.inflate(com.ss.android.article.browser.R.layout.feed_item, parent, false);
            holder = new ArticleFeedViewHolder(this.mContext, this.mNetworkMonitor, this.mFeedItemBehavior,
                    this.mArticleActionHelper, this.mFeedType, this.mTimeFormatter, this.mActualItemImageWidth,
                    this.mActualItemImageHeight, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.n,
                    this.mPopupToast, this.mDiggAnimationView);
            holder.articleShareHelper = this.mArticleShareHelper;
            holder.mLargeItemAvatarLoader = this.mLargeItemAvatarLoader;
            holder.mOneOrThreeItemAvatarLoader = this.mOneOrThreeItemAvatarLoader;
            holder.initImage3Layout(convertView);
            convertView.setTag(holder);
        } else {
            Object tag = convertView.getTag();
            if (!(tag instanceof ArticleFeedViewHolder)) {
                holder = new ArticleFeedViewHolder(this.mContext, this.mNetworkMonitor,
                        this.mFeedItemBehavior, this.mArticleActionHelper, this.mFeedType, this.mTimeFormatter,
                        this.mActualItemImageWidth, this.mActualItemImageHeight, this.mActualLargeImageWidth,
                        this.mMaxLargeImageHeight, this.n, this.mPopupToast, this.mDiggAnimationView);
                holder.initWithSomeOther((BaseFeedViewHolder) tag);
                convertView.setTag(holder);
                holder.articleShareHelper = this.mArticleShareHelper;
                holder.mLargeItemAvatarLoader = this.mLargeItemAvatarLoader;
                holder.mOneOrThreeItemAvatarLoader = this.mOneOrThreeItemAvatarLoader;
            }
        }

        ArticleFeedViewHolder articleFeedViewHolder = (ArticleFeedViewHolder) convertView.getTag();
        boolean reuseItem = articleFeedViewHolder.mCellRef == cellRef
                && android.support.design.a.reuseItem(convertView);
        try {
            cellRef.reuseItem = reuseItem;
            articleFeedViewHolder.a(cellRef, position);
        } catch (Exception e) {
            Logger.throwExceptionInDebug(e);
        }
        articleFeedViewHolder.mDeleteTextView.setVisibility(this.showDeleteView ? View.VISIBLE : View.GONE);
        Article article = cellRef.article;
        boolean sendEveryItemShow = this.mAppData.sendEveryItemShow();
        if (reuseItem
                && !sendEveryItemShow
                && (Logger.debug())) {
            Logger.d("ArticleFeedPresenter", "skip show event for item view: " + position);
        }
        this.a(reuseItem, sendEveryItemShow, cellRef, article, articleFeedViewHolder);
        return convertView;
    }

    public final void c(boolean postSync) {
        IVideoControllerContext videoControllerContext = this.mVideoControllerContext;
        if (videoControllerContext != null) {
            IVideoController videoController = videoControllerContext.getVideoController();
            if (videoController != null) {
                Article article = this.mAppData.article;
                if (article != null
                        && (android.support.design.a.isTextEquals(article.videoId, videoController.getVideoId()))) {
                    videoController.syncPosition(postSync);
                }
            }
        }
    }

    private View getEmbeddedAdConvertView(int position, CellRef cellRef, View convertView, ViewGroup parent) {
        View v12;
        com.ss.android.article.base.feature.feed.vh.a v2;
        View v16 = convertView == null || convertView.getTag() instanceof BaseFeedViewHolder ? convertView : null;
        if (v16 == null) {
            View view = this.mLayoutInflater.inflate(com.ss.android.article.browser.R.layout.feed_item, parent, false);
            v2 = new com.ss.android.article.base.feature.feed.vh.a(this.mContext,
                    this.mNetworkMonitor,
                    this.mFeedItemBehavior,
                    this.mArticleActionHelper,
                    this.mFeedType,
                    this.mTimeFormatter,
                    this.mActualItemImageWidth,
                    this.mActualItemImageHeight,
                    this.mActualLargeImageWidth,
                    this.mMaxLargeImageHeight,
                    this.mActualLargeImageHeight,
                    this.n);
            v2.initImage3Layout(view);
            view.setTag(v2);
            v12 = view;
        } else {
            Object tag = v16.getTag();
            if (!(tag instanceof com.ss.android.article.base.feature.feed.vh.a)) {
                v2 = new com.ss.android.article.base.feature.feed.vh.a(this.mContext,
                        this.mNetworkMonitor,
                        this.mFeedItemBehavior,
                        this.mArticleActionHelper,
                        this.mFeedType,
                        this.mTimeFormatter,
                        this.mActualItemImageWidth,
                        this.mActualItemImageHeight,
                        this.mActualLargeImageWidth,
                        this.mMaxLargeImageHeight,
                        this.mActualLargeImageHeight,
                        this.n);
                v2.initWithSomeOther(((BaseFeedViewHolder) tag));
                v16.setTag(v2);
                v12 = v16;
            } else {
                v2 = (com.ss.android.article.base.feature.feed.vh.a) v16.getTag();
                v12 = v16;
            }
        }

        int v3 = v2.mCellRef != cellRef || !android.support.design.a.reuseItem(v12) ? 0 : 1;
        try {
            v2.a(cellRef, position);
        } catch (Exception v4) {
            Logger.throwExceptionInDebug(v4);
        }

        JSONObject v10 = new JSONObject();
        try {
            if (android.support.design.a.isTextEmpty(cellRef.feedCallAppAd.logExtra)) {
            } else {
                v10.put("log_extra", cellRef.feedCallAppAd.logExtra);
                v2.feedCallAppAdLogExtra = cellRef.feedCallAppAd.logExtra;
            }
        } catch (Exception v4) {
        }

        if (!this.mAppData.sendEveryItemShow() && v3 != 0) {
            if (Logger.debug()) {
                Logger.d("ArticleFeedPresenter", "skip show event for ad view: " + position);
            }
        } else if (cellRef.feedCallAppAd != null) {
            MobAdClickCombiner.onAdEvent(this.mContext, "embeded_ad", "show", cellRef.feedCallAppAd.id, 0, v10, 2);
            cellRef.feedCallAppAd.a(this.mContext, "card_show");
            AppUtil.a(cellRef.feedCallAppAd.trackUrlList, this.mContext);
        } else {
            if (Logger.debug()) {
                Logger.d("ArticleFeedPresenter", "skip show event for ad view: " + position);
            }
        }

        String v3_1 = "";
        if (cellRef.feedCallAppAd != null) {
            v3_1 = String.valueOf(cellRef.feedCallAppAd.id);
        }

        v2.a(2, String.valueOf(cellRef.adId), v3_1, cellRef.logExtra);
        v2.adId = v3_1;
        return v12;
    }

    public final void onPrimaryPageChanged(boolean arg2) {
        if (arg2) {
            android.support.design.a.b(this.mArticleDetailCache);
        } else {
            this.h();
        }
    }

    public final void onDestroy() {
        AsyncLoader v2 = null;
        if (this.mPopupToast != null) {
            this.mPopupToast.onDestroy();
        }

        if (this.mAsyncLoader != null) {
            this.mAsyncLoader.stop();
        }

        if (this.mTaskInfo != null) {
            this.mTaskInfo.a = true;
        }

        if (this.mItemImageLoader != null) {
            this.mItemImageLoader.onDestroy();
        }

        if (this.mLargeImageLoader != null) {
            this.mLargeImageLoader.onDestroy();
        }

        if (this.mLargeItemAvatarLoader != null) {
            this.mLargeItemAvatarLoader.onDestroy();
        }

        if (this.mFeedAvatarLoader != null) {
            this.mFeedAvatarLoader.onDestroy();
        }

        if (this.mOneOrThreeItemAvatarLoader != null) {
            this.mOneOrThreeItemAvatarLoader.onDestroy();
        }

        this.mAsyncLoader = v2;
        this.mItemImageLoader = null;
        this.mLargeImageLoader = null;
        this.mLargeItemAvatarLoader = null;
        this.mFeedAvatarLoader = null;
        this.mOneOrThreeItemAvatarLoader = null;
        this.h();
        if (this.mMoreActionCallback != null) {
            CallbackCenter.removeCallback(com.ss.android.j.b.callbackTypeNightModeChanged, this.mMoreActionCallback);
        }
    }

    private View getFeedDownloadConvertView(int arg18, CellRef arg19, View arg20, ViewGroup arg21) {
        JSONObject v10;
        AppAdViewHolder v15_2;
        AppAdViewHolder v15_1;
        View v12;
        AppAdViewHolder v2;
        View v16 = arg20 == null || ((arg20.getTag() instanceof BaseFeedViewHolder)) ? arg20 : null;
        if (v16 == null) {
            View v15 = this.mLayoutInflater.inflate(com.ss.android.article.browser.R.layout.feed_item, arg21, false);
            v2 = new AppAdViewHolder(this.mContext, this.mNetworkMonitor, this.mFeedItemBehavior,
                    this.mArticleActionHelper, this.mFeedType, this.mTimeFormatter, this.mActualItemImageWidth,
                    this.mActualItemImageHeight, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.mActualLargeImageHeight,
                    this.n);
            v2.initImage3Layout(v15);
            v15.setTag(v2);
            v12 = v15;
            v15_2 = v2;
        } else {
            v15_2 = (AppAdViewHolder) v16.getTag();
            if (!(v15_2 instanceof AppAdViewHolder)) {
                v2 = new AppAdViewHolder(this.mContext, this.mNetworkMonitor, this.mFeedItemBehavior, this.mArticleActionHelper, this.mFeedType, this.mTimeFormatter, this.mActualItemImageWidth, this.mActualItemImageHeight, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.mActualLargeImageHeight, this.n);
                v2.initWithSomeOther(v15_2);
                v16.setTag(v2);
                v15_2 = v2;
                v12 = v16;
            } else {
                v12 = v16;
            }
        }

        if (arg19 == null) {
            View v2_1 = v12;
            return v2_1;
        }

        int v3 = v15_2.mCellRef != arg19 || !android.support.design.a.reuseItem(v12) ? 0 : 1;
        if (v3 == 0) {
            v15_2.mDownloadInfo = null;
        }

        try {
            v15_2.a(arg19, arg18);
        } catch (Exception v2_2) {
            Logger.throwExceptionInDebug(((Throwable) v2_2));
        }

        JSONObject v2_3 = null;
        try {
            if (!android.support.design.a.isTextEmpty(arg19.downloadAppAd.logExtra)) {
                v2_3 = new JSONObject();
                v2_3.put("log_extra", arg19.downloadAppAd.logExtra);
                v15_2.feedCallAppAdLogExtra = arg19.downloadAppAd.logExtra;
            }
            v10 = v2_3;
        } catch (Exception v2_2) {
            v10 = null;
        }

        if (!this.mAppData.sendEveryItemShow() && v3 != 0) {
            if (Logger.debug()) {
                Logger.d("ArticleFeedPresenter", "skip show event for ad view: " + arg18);
            }
        } else if (arg19.downloadAppAd != null) {
            MobAdClickCombiner.onAdEvent(this.mContext, "feed_download_ad", "card_show", arg19.downloadAppAd.id, 0, v10, 2);
            if (arg19 != null && arg19.downloadAppAd != null) {
                AppUtil.a(arg19.downloadAppAd.trackUrlList, this.mContext);
            }

            MobAdClickCombiner.onAdEvent(this.mContext, "embeded_ad", "show", arg19.downloadAppAd.id, 0, v10, 2);
        } else {
            if (Logger.debug()) {
                Logger.d("ArticleFeedPresenter", "skip show event for ad view: " + arg18);
            }
        }
        String v2_4 = "";
        if (arg19.downloadAppAd != null) {
            android.support.design.a.isTextEmpty((String) null);
            if (arg19.downloadAppAd.id > 0) {
                v2_4 = String.valueOf(arg19.downloadAppAd.id);
            }
        }

        v15_2.a(2, String.valueOf(arg19.adId), v2_4, arg19.logExtra);
        v15_2.adId = v2_4;
        return v12;
    }

    public final void onResume() {
        if (this.mAsyncLoader != null) {
            this.mAsyncLoader.resume();
        }

        if (this.mItemImageLoader != null) {
            this.mItemImageLoader.onPause();
        }

        if (this.mLargeImageLoader != null) {
            this.mLargeImageLoader.onPause();
        }

        if (this.mLargeItemAvatarLoader != null) {
            this.mLargeItemAvatarLoader.onPause();
        }

        if (this.mFeedAvatarLoader != null) {
            this.mFeedAvatarLoader.onPause();
        }

        if (this.mOneOrThreeItemAvatarLoader != null) {
            this.mOneOrThreeItemAvatarLoader.onPause();
        }
    }

    private View getLbsAdConvertView(int position, CellRef cellRef, View convertView, ViewGroup parent) {
        View v3;
        LbsAdViewHolder v2;
        View v16 = convertView == null || ((convertView.getTag() instanceof BaseFeedViewHolder)) ? convertView : null;
        if (v16 == null) {
            View v15 = this.mLayoutInflater.inflate(com.ss.android.article.browser.R.layout.feed_item, parent, false);
            v2 = new LbsAdViewHolder(this.mContext, this.mNetworkMonitor, this.mFeedItemBehavior, this.mArticleActionHelper, this.mFeedType, this.mTimeFormatter, this.mActualItemImageWidth, this.mActualItemImageHeight, this.mActualLargeImageWidth, this.mMaxLargeImageHeight, this.mActualLargeImageHeight, this.n);
            v2.initImage3Layout(v15);
            v15.setTag(v2);
            v3 = v15;
        } else {
            Object tag = v16.getTag();
            if (!(tag instanceof LbsAdViewHolder)) {
                v2 = new LbsAdViewHolder(this.mContext,
                        this.mNetworkMonitor,
                        this.mFeedItemBehavior,
                        this.mArticleActionHelper,
                        this.mFeedType,
                        this.mTimeFormatter,
                        this.mActualItemImageWidth,
                        this.mActualItemImageHeight,
                        this.mActualLargeImageWidth,
                        this.mMaxLargeImageHeight,
                        this.mActualLargeImageHeight,
                        this.n);
                v2.initWithSomeOther(((BaseFeedViewHolder) tag));
                v16.setTag(v2);
                v3 = v16;
            } else {
                v2 = (LbsAdViewHolder) tag;
                v3 = v16;
            }
        }

        int v4 = v2.mCellRef != cellRef || !android.support.design.a.reuseItem(v3) ? 0 : 1;
        try {
            v2.a(cellRef, position);
        } catch (Exception v5) {
            Logger.throwExceptionInDebug(v5);
        }

        if (cellRef.embeddedAd != null) {
            v2.feedCallAppAdLogExtra = cellRef.embeddedAd.logExtra;
        }

        if (!this.mAppData.sendEveryItemShow() && v4 != 0) {
            if (Logger.debug()) {
                Logger.d("ArticleFeedPresenter", "skip show event for lbsAd view: " + position);
            }
        } else if (cellRef.embeddedAd != null) {
            BaseAdsData.trackAdShow(this.mContext, "embeded_ad", cellRef.embeddedAd, 0);
        } else {
            if (Logger.debug()) {
                Logger.d("ArticleFeedPresenter", "skip show event for lbsAd view: " + position);
            }
        }

        String v4_1 = "";
        if (cellRef.embeddedAd != null) {
            v4_1 = String.valueOf(cellRef.embeddedAd.id);
        }

        v2.a(2, String.valueOf(cellRef.adId), v4_1, cellRef.logExtra);
        v2.adId = v4_1;
        return v3;
    }

    public final void f() {
        int i = 0;
        for (; i < mCellRefList.size(); i++) {
            CellRef cellRef = this.mCellRefList.get(i);
            if (cellRef.cellType == -1) {
                this.mLastReadCellRef = cellRef;
                break;
            }
        }

        if (this.mLastReadCellRef != null && i > 1) {
            this.mCellRefBeforeLastRead = this.mCellRefList.get(i - 1);
        }
    }

    public final void onPause() {
    }

    private View getImage3ConvertView(int position, CellRef cellRef, View convertView, ViewGroup container) {
        com.ss.android.article.base.feature.feed.vh.g holder;
        if (convertView != null && !(convertView.getTag() instanceof BaseFeedViewHolder)) {
            convertView = null;
        }

        if (convertView == null) {
            convertView = this.mLayoutInflater.inflate(com.ss.android.article.browser.R.layout.feed_item, container, false);
            holder = new com.ss.android.article.base.feature.feed.vh.g(
                    this.mContext,
                    this.mNetworkMonitor,
                    this.mFeedItemBehavior,
                    this.mArticleActionHelper,
                    this.mFeedType,
                    this.mTimeFormatter,
                    this.mActualItemImageWidth,
                    this.mActualItemImageHeight,
                    this.mActualLargeImageWidth,
                    this.mMaxLargeImageHeight, this.n);
            holder.initImage3Layout(convertView);
            convertView.setTag(holder);
        } else {
            Object tag = convertView.getTag();
            if (!(tag instanceof com.ss.android.article.base.feature.feed.vh.g)) {
                holder = new com.ss.android.article.base.feature.feed.vh.g(
                        this.mContext,
                        this.mNetworkMonitor,
                        this.mFeedItemBehavior,
                        this.mArticleActionHelper,
                        this.mFeedType,
                        this.mTimeFormatter,
                        this.mActualItemImageWidth,
                        this.mActualItemImageHeight,
                        this.mActualLargeImageWidth,
                        this.mMaxLargeImageHeight, this.n);
                holder.initWithSomeOther(((BaseFeedViewHolder) tag));
                convertView.setTag(holder);
            } else {
                holder = (com.ss.android.article.base.feature.feed.vh.g) tag;
            }
        }

        if (holder.mCellRef == cellRef) {
            android.support.design.a.reuseItem(convertView);
        }

        try {
            holder.a(cellRef, position);
        } catch (Exception v3) {
            Logger.throwExceptionInDebug(((Throwable) v3));
        }

        String v3_1 = null;
        try {
            if (android.support.design.a.isTextEmpty(v3_1)) {
            } else {
                new JSONObject().put("log_extra", null);
                holder.feedCallAppAdLogExtra = null;
            }
        } catch (Exception v3) {
        }

        this.mAppData.sendEveryItemShow();
        if (Logger.debug()) {
            Logger.d("ArticleFeedPresenter", "skip show event for ad view: " + position);
        }

        holder.a(2, String.valueOf(cellRef.adId), "", cellRef.logExtra);
        holder.adId = "";
        return convertView;
    }

    public final int g() {
        return 5;
    }

    private View getFeedStickConvertView(int position, CellRef cellRef, View convertView, ViewGroup container) {
        FeedStickViewHolder holder;
        convertView = convertView == null || ((convertView.getTag() instanceof FeedStickViewHolder)) ? convertView : null;
        if (convertView == null) {
            convertView = this.mLayoutInflater.inflate(com.ss.android.article.browser.R.layout.feed_stick_layout, container, false);
            holder = new FeedStickViewHolder(this.mContext, this.mFeedItemBehavior);
            if (convertView != null) {
                holder.mItemView = convertView;
                holder.mFeedStickContentTitle = convertView.findViewById(com.ss.android.article.browser.R.id.feed_stick_content_title);
                holder.mFeedStickPopIcon = convertView.findViewById(com.ss.android.article.browser.R.id.feed_stick_pop_icon);
                holder.mFeedStickDivider = convertView.findViewById(com.ss.android.article.browser.R.id.feed_stick_divider);
                holder.mItemView.setOnClickListener(holder.z);
                holder.mFeedStickPopIcon.setOnClickListener(holder.y);
            }
            convertView.setTag(holder);
        } else {
            holder = (FeedStickViewHolder) convertView.getTag();
        }

        boolean v1_1 = holder.u != cellRef || !android.support.design.a.reuseItem(convertView) ? false : true;
        if (cellRef != null) {
            try {
                holder.t = position;
                holder.u = cellRef;
                boolean v0_1 = AppData.isNightMode();
                if (v0_1 != holder.v) {
                    holder.v = v0_1;
                    holder.mFeedStickContentTitle.setTextColor(holder.w.getColorStateList(com.ss.android.article.browser.R.color.item_text));
                    holder.mFeedStickDivider.setBackgroundColor(ContextCompat.getColor(((FeedStickViewHolder) holder).o, R.color.divider));
                    holder.mFeedStickPopIcon.setImageDrawable(ContextCompat.getDrawable(((FeedStickViewHolder) holder).o, R.drawable.m7));
                    ClickableBackgroundCompat.setClickableBackground(holder.mItemView, ((FeedStickViewHolder) holder).v);
                }

                if (cellRef.article == null) {

                } else if (android.support.design.a.isTextEmpty(cellRef.article.title)) {

                } else {
                    holder.mFeedStickContentTitle.setText(((FeedStickViewHolder) holder).a(cellRef.article.title));
                }
            } catch (Exception v0) {
                Logger.throwExceptionInDebug(v0);
            }
        }

        Article article = cellRef.article;
        boolean v2 = this.mAppData.sendEveryItemShow();
        if ((v1_1) && !v2 && (Logger.debug())) {
            Logger.d("ArticleFeedPresenter", "skip show event for item view: " + position);
        }
        this.a(v1_1, v2, cellRef, article, holder);
        return convertView;
    }

    private void h() {
        IVideoControllerContext videoControllerContext = this.mVideoControllerContext;
        if (videoControllerContext != null) {
            IVideoController videoController = videoControllerContext.getVideoController();
            if (videoController != null
                    && !videoController.isFullScreen()
                    && !android.support.design.a.isTextEmpty(videoController.getCategory())
                    && (videoController.getCategory().equals(this.mCategoryName))) {
                videoController.releaseMedia();
            }
        }
    }

    public final void onStop() {
        if (this.mItemImageLoader != null) {
            this.mItemImageLoader.onStop();
        }

        if (this.mLargeImageLoader != null) {
            this.mLargeImageLoader.onStop();
        }

        if (this.mLargeItemAvatarLoader != null) {
            this.mLargeItemAvatarLoader.onStop();
        }

        if (this.mFeedAvatarLoader != null) {
            this.mFeedAvatarLoader.onStop();
        }

        if (this.mOneOrThreeItemAvatarLoader != null) {
            this.mOneOrThreeItemAvatarLoader.onStop();
        }
    }
}

